<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Infotech Ltd.
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2006/02/27 22:02:05 $)
// $RCSfile: functions_clirebuildindex.php,v $ : $Revision: 1.1 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

/**
* Go through the index rebuild pass
*/
function processPass($_startat, $_postpass, $_totalposts)
{
	global $dbCore, $_SWIFT, $cli;

	// Now lets fetch the ticket posts
	unset($lastticketpostid);
	$_searchticketidlist = array();
	$dbCore->query("SELECT `ticketpostid`, `subject`, `contents` FROM `". TABLE_PREFIX ."ticketposts` WHERE `ticketpostid` >= '". intval($_startat) ."' ORDER BY `ticketpostid` ASC LIMIT ". intval($_postpass) .";", 2);
	while ($dbCore->nextRecord(2))
	{
		$lastticketpostid = $dbCore->Record2["ticketpostid"];
		$_searchticketidlist[] = $dbCore->Record2;
//		echo "Processing: $lastticketpostid<BR>";
		$_SWIFT["rebuild"]["processcount"]++;
	}

	if ($_totalposts)
	{
		$percent = $_SWIFT["rebuild"]["processcount"]*(100/$_totalposts);
	} else {
		$percent = 100;
	}
	$_SWIFT["rebuild"]["percent"] = $percent;
	$_SWIFT["rebuild"]["lastticketpostid"] = $lastticketpostid;

	foreach ($_searchticketidlist as $key=>$val)
	{
		$_wordcount += buildTicketPostIndex($val["ticketpostid"], $val["subject"], $val["contents"]);
	}

	$cli->message(sprintf($_SWIFT["language"]["rebuildingpost"], intval($lastticketpostid), intval($_SWIFT["rebuild"]["percent"]))."%", CLI_INFO);

	return $lastticketpostid;
}
?>